﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

/// <summary>
/// Summary description for SendMail
/// </summary>
public class SendMail
{
	  #region Constructors
    public SendMail()
	{
    }
    #endregion

    #region Methods

    public bool SendEMail(string from_address, string from_password,
       string from_displayName, string to_address,
       string subject, string body)
    {
        //--Create Mail
        MailMessage msg = new MailMessage();
        msg.To.Add(to_address);
        msg.From = new MailAddress(from_address, from_displayName,
            System.Text.Encoding.UTF8);
        msg.Subject = subject;
        msg.SubjectEncoding = System.Text.Encoding.UTF8;
        msg.Body = body;
        msg.BodyEncoding = System.Text.Encoding.UTF8;
        //--Allow send HTML code in Mail
        msg.IsBodyHtml = true;
        //--Priority of Mail
        msg.Priority = MailPriority.High;
        //--Authentication consist of user+pass
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential
        (from_address, from_password);
       
        client.Port = 587;
        //--Address server SMTP of google
        client.Host = "smtp.gmail.com";
        
        client.EnableSsl = true;
        //--Start proccess send Email
        try { client.Send(msg); }
        catch { return false; }  
        return true; 
    }
    #endregion
}